package data;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import dataservice.EduPlanDS;

public class EduPlanData extends UnicastRemoteObject implements EduPlanDS {

	protected EduPlanData() throws RemoteException {
		super();
	}
 
	private static final long serialVersionUID = 1L;

	public ArrayList<String> getPlan(String institute) throws RemoteException {
		ArrayList<String> planList = new ArrayList<String>();
		try {
			String text = institute + ".txt";
			BufferedReader br = new BufferedReader(new FileReader(text));
			String temp;
			while ((temp = br.readLine()) != null) {
				planList.add(temp);
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return planList;
	}

	public boolean changePlan(ArrayList<String> planList, String institute)
			throws RemoteException {
		boolean change = false;
		try{
			String text = institute + ".txt";
			FileWriter fw = new FileWriter(text);
			for(int i = 0;i<planList.size();i++){
				fw.write(planList.get(i) + "\r\n");
			}
			change = true;
			fw.close();
		}catch(Exception e){
			e.printStackTrace();
		}

		return change;
	}

}
